<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/commons/global.jsp"%>

<div id="audio-info-win" class="easyui-window" title="${audio.title }"
	style="width: 1000px; height: 500px"
	data-options="iconCls:'icon-cog',modal:true,openAnimation:'fade',closeAnimation:'slide',cache:false,collapsible:false,minimizable:false,maximizable:false">


	<form id="updateVideoButtonInputForm" method="post"
		style="display: none;" enctype="multipart/form-data">
		<input name="eVideoId" value="${audio.id}" style="display: none;" />
		<input id="updateVideoButtonInput" type="file" name="coverFile"
			accept="image/bmp,image/png,image/gif,image.jpg,image/jpeg"
			style="display: none;">
	</form>

	<a id="audio-info-win-pg-save" href="javascript:;"
		onclick="audio_info_win_pg_accept()" class="easyui-linkbutton"
		data-options="iconCls:'icon-save'" style="float: right;">保存</a>
	<table id="audio-info-win-pg" class="easyui-propertygrid"
		style="width: 100%; height: 100%;"
		data-options="showGroup:false,scrollbarSize:0">
	</table>

	<div id="audio-info-status-win" class="easyui-window" title="状态设置"
		style="width: 200px; height: 200px;"
		data-options="iconCls:'icon-cog',modal:true,openAnimation:'fade',closeAnimation:'slide',cache:false,collapsible:false,minimizable:false,maximizable:false">
		<input id="audio_info_StatusQue" style="display: none;" />
	</div>


	<input id="audio-info-win-pg-info" value="${audio.info }"
		style="display: none;" /> <input id="audio-info-win-pg-summary"
		value="${audio.summary }" style="display: none;" />
</div>

<script type="text/javascript">
	function audio_info_win_pg_accept() {
		try {
			var id = audio_info_win_pg.propertygrid('options').data.rows[0].value;
			var title = audio_info_win_pg.propertygrid('options').data.rows[1].value;
			if (!title) {
				$.messager.alert('提示', '标题不能为空', 'warning');
				return;
			}
			var sort = audio_info_win_pg.propertygrid('options').data.rows[3].value;
			var playtime = audio_info_win_pg.propertygrid('options').data.rows[4].value;
			var summary = audio_info_win_pg.propertygrid('options').data.rows[5].value;
			var info = audio_info_win_pg.propertygrid('options').data.rows[6].value;
			var status = audio_info_StatusQue.combobox('getValue');
			var _Data = {
				id : id,
				title : title,
				sort : sort,
				playtime : playtime,
				summary : summary,
				info : info,
				status : status
			};

			$
					.ajax({
						data : _Data,
						async : false,
						type : 'POST',
						url : baseUrl + '/audio/update',
						success : function(data) {
							if (data.responseCode == '000') {
								audioListDatagrid.datagrid('endEdit',
										audioSelectIndex);

								audioListDatagrid.datagrid('acceptChanges');

								audioSelectIndex = undefined;
								audioSelectRow = undefined;
								audioEditIndex = undefined;
								audioEditRow = undefined;

								$.messager.alert('提示', '修改成功', 'info');
							} else {
								$.messager.alert('提示', data.responseMessage,
										'error');
							}
						}
					});
		} catch (e) {
		}
	}
</script>
<script type="text/javascript">
	var audio_info_status_win = undefined;
	var audio_info_win_pg = undefined;
	var audio_info_StatusQue = undefined;
	$(function() {
		var audio_info_win = $('#audio-info-win').window({
			onBeforeClose : function() {

			},
			onClose : function() {
				audio_info_win.panel('destroy');
			}
		});

		var pro = {
			total : 10,
			rows : []
		};
		var idRow = {
			name : 'ID',
			value : "${audio.id}",
			group : '${audio.id}'
		};

		var titleRow = {
			name : '标题',
			value : "${audio.title}",
			group : '${audio.id}',
			"editor" : "text"
		};

		var statusRow = {
			name : '状态',
			value : '<div onclick="$(\'#audio-info-status-win\').window(\'open\');">${audio.statusMsg}</div>',
			group : '${audio.id}'
		};

		var sortRow = {
			name : '排序',
			value : "${audio.sort}",
			group : '${audio.id}',
			"editor" : "text"
		};
		var playtimeRow = {
			name : '播放时间(秒)',
			value : "${audio.playtime}",
			group : '${audio.id}',
			"editor" : "text"
		};
		var summaryRow = {
			name : '简介',
			value : $('#audio-info-win-pg-summary').val(),
			group : '${audio.id}',
			"editor" : "text"
		};
		var infoRow = {
			name : '详细介绍',
			value : $('#audio-info-win-pg-info').val(),
			group : '${audio.id}',
			"editor" : "text"
		};

		var entityRow = {
			name : '视频实体',
			value : "${audio.entity}",
			group : '${audio.id}'
		};

		var sourcesRow = {
			name : '资源',
			value : "${audio.sources}",
			group : '${audio.id}'
		};

		var skeyRow = {
			name : '资源令牌',
			value : "${audio.skey}",
			group : '${audio.id}'
		};

		var createTimeRow = {
			name : '创建时间',
			value : "${audio.createTime}",
			group : '${audio.id}'
		};

		var updateTimeRow = {
			name : '更新时间',
			value : "${audio.updateTime}",
			group : '${audio.id}'
		};

		var coverUrlRow = {
			name : '封面',
			value : '<img style="width: 480px; height: 300px;" id="updateVideoImg" src="${audio.coverUrl}"/>',
			group : '${audio.id}'
		};
		pro.rows.push(idRow);
		pro.rows.push(titleRow);
		pro.rows.push(statusRow);
		pro.rows.push(sortRow);

		pro.rows.push(playtimeRow);
		pro.rows.push(summaryRow);
		pro.rows.push(infoRow);

		pro.rows.push(entityRow);
		pro.rows.push(sourcesRow);
		pro.rows.push(skeyRow);
		pro.rows.push(createTimeRow);
		pro.rows.push(updateTimeRow);
		pro.rows.push(coverUrlRow);

		audio_info_win_pg = $('#audio-info-win-pg').propertygrid({
			'data' : pro
		});

		$('#updateVideoImg').click(function() {
			$('#updateVideoButtonInput').trigger('click');
		});

		$('#updateVideoButtonInput').change(function() {
			var _this = $(this);
			if (_this.val() && _this.val().length > 0) {
				var size = _this[0].files[0].size / 1024;
				if (size > (3 * 1024)) {
					$('#' + inputName).val("");
					$.message.alert('提示', '图片不能大于3M', 'warning');
					return;
				}
			}
			$('#updateVideoButtonInputForm').form().submit();
		});

		$('#updateVideoButtonInputForm').form({
			url : baseUrl + '/audio/updateCover',
			iframe : false,
			onSubmit : function(param) {
			},
			onProgress : function(percent) {
				$.messager.progress({
					value : percent
				});
			},
			success : function(data) {
				$.messager.progress('close');
				data = eval("(" + data + ")");
				console.info(data)
				console.info(data.data)

				$('#updateVideoImg').attr('src', data.data);
			}
		});

		$('.easyui-combobox').combobox();
		$('.easyui-linkbutton').linkbutton();
		// 		$('.easyui-window').window();
		// 		$('.easyui-propertygrid').propertygrid();

		audio_info_status_win = $('#audio-info-status-win').window();
		audio_info_status_win.window('close');

		audio_info_StatusQue = $('#audio_info_StatusQue')
				.combobox(
						{
							data : [ {
								"statusCode" : 1,
								"statusMsg" : "已发布",
								"selected" : "${audio.statusCode}" == "1"
							}, {
								"statusCode" : 2,
								"statusMsg" : "已下线",
								"selected" : "${audio.statusCode}" == "2"
							}, {
								"statusCode" : 3,
								"statusMsg" : "待发布",
								"selected" : "${audio.statusCode}" == "3"
							} ],
							valueField : 'statusCode',
							textField : 'statusMsg',
							onChange : function(newValue, oldValue) {
								var statusMsg = "";
								if (newValue == 1) {
									statusMsg = '已发布';
								} else if (newValue == 2) {
									statusMsg = '已下线';
								} else if (newValue == 3) {
									statusMsg = '待发布';
								}
								pro.rows[2].value = '<div onclick="$(\'#audio-info-status-win\').window(\'open\');"> '
										+ statusMsg + '   </div>';
								audio_info_win_pg.propertygrid('refreshRow', 2);
								audio_info_win_pg.propertygrid('options').data = pro;
							}
						});

	});
</script>

